home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-24 | 7.0 KB | 272 lines | [TEXT/MMCC] |
- // ===========================================================================
- // CNetDemoApp.cp ©1995 Metrowerks Inc. All rights reserved.
- // ===========================================================================
- //
- // Example program showing how to use UModalDialogs
-
- #include "CNetDemoApp.h"
-
- #include "InPoint.h"
- #include "OutPoint.h"
-
- #include "DemoDoc.h"
-
- #include <LApplication.h>
- #include <LGrowZone.h>
- #include <LWindow.h>
- #include <UMemoryMgr.h>
- #include <UDrawingState.h>
- #include <URegistrar.h>
- #include <UReanimator.h>
-
- #include <LEditField.h>
- #include <LTabGroup.h>
- #include <LCaption.h>
- #include <LRadioGroup.h>
- #include <LStdControl.h>
- #include <LDialogBox.h>
- #include <UModalDialogs.h>
- #include <PP_Messages.h>
-
- #include <string.h>
-
- #include "APane.h"
-
- const ResIDT WIND_NewSession = 128;
- const PaneIDT pTCPButton = 1;
- const PaneIDT pAtalkButton = 2;
- const PaneIDT pAddress = 11;
-
- /*
- const ResIDT WIND_Dashboard = 200;
- const PaneIDT capt_Number = 301;
- const PaneIDT capt_String = 302;
-
- const MessageT msg_SetNumber = 1000;
- const MessageT msg_SetString = 2000;
- const MessageT msg_SetBoth = 3000;
-
- const ResIDT WIND_SetNumber = 1000;
- const PaneIDT edit_Number = 1001;
-
- const ResIDT WIND_SetString = 2000;
- const PaneIDT edit_String = 2001;
-
- const ResIDT WIND_SetBoth = 3000;
- const PaneIDT edit_Number1 = 3001;
- const PaneIDT edit_String1 = 3002;
- */
-
-
- // ===========================================================================
- // • Main Program
- // ===========================================================================
-
- void main(void)
- {
- try {
- // Set Debugging options
- SetDebugThrow_(debugAction_Alert);
- SetDebugSignal_(debugAction_Alert);
-
- InitializeHeap(3); // Initialize Memory Manager
- // Parameter is number of Master Pointer
- // blocks to allocate
-
- // Initialize standard Toolbox managers
- UQDGlobals::InitializeToolbox(&qd);
- InitOpenTransport();
-
- new LGrowZone(20000); // Install a GrowZone function to catch
- // low memory situations.
- // Parameter is size of reserve memory
- // block to allocated. The first time
- // the GrowZone function is called,
- // there will be at least this much
- // memory left (so you'll have enough
- // memory to alert the user or finish
- // what you are doing).
-
- CNetDemoApp theApp; // Create instance of your Application
- theApp.Run(); // class and run it
- }
- catch(...) {
- DebugStr("\pSomething's really hosed");
- }
- }
-
-
- // ===========================================================================
- // • CNetDemoApp Class
- // ===========================================================================
-
- // ---------------------------------------------------------------------------
- // • CNetDemoApp
- // ---------------------------------------------------------------------------
- // Constructor
-
- CNetDemoApp::CNetDemoApp()
- {
- // Register classes for objects created from 'PPob' resources
- // For PowerPlant classes, you can copy the necessary RegisterClass
- // calls from PPobClasses.cp
- //
- // For your own classes, you must use the same four-character ID as
- // you specify in the 'PPob' resource (or in Constructor).
- // PowerPlant reserves all ID's composed entirely of lower case
- // letters.
- //
- // The convention in PowerPlant is to define a local enumerated
- // constant called class_ID for the four-character ID of each class.
-
- URegistrar::RegisterClass(LWindow::class_ID, LWindow::CreateWindowStream);
- URegistrar::RegisterClass(LEditField::class_ID, LEditField::CreateEditFieldStream);
- URegistrar::RegisterClass(LTabGroup::class_ID, LTabGroup::CreateTabGroupStream);
- URegistrar::RegisterClass(LCaption::class_ID, LCaption::CreateCaptionStream);
- URegistrar::RegisterClass(LStdButton::class_ID, LStdButton::CreateStdButtonStream);
- URegistrar::RegisterClass(LStdRadioButton::class_ID, LStdRadioButton::CreateStdRadioButtonStream);
- URegistrar::RegisterClass(LRadioGroup::class_ID, LRadioGroup::CreateRadioGroupStream);
- URegistrar::RegisterClass(LDialogBox::class_ID, LDialogBox::CreateDialogBoxStream);
- URegistrar::RegisterClass(APane::class_ID, APane::CreateAPaneStream);
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~CNetDemoApp
- // ---------------------------------------------------------------------------
- // Destructor
-
- CNetDemoApp::~CNetDemoApp()
- {
- // +++ Add code here to cleanup (if necessary) before quitting
- }
-
-
- // ---------------------------------------------------------------------------
- // • ObeyCommand
- // ---------------------------------------------------------------------------
- // Respond to commands
-
- Boolean
- CNetDemoApp::ObeyCommand(
- CommandT inCommand,
- void *ioParam)
- {
- Boolean cmdHandled = true;
-
- switch (inCommand) {
-
- case cmd_New:
- case 999:
- SpawnSender(inCommand == cmd_New); // yes this is ugly... deal with it
- break;
-
- // +++ Add cases here for the commands you handle
- // Remember to add same cases to FindCommandStatus below
- // to enable/disable the menu items for the commands
-
- default:
- cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- // ---------------------------------------------------------------------------
- // Pass back status of a (menu) command
-
- void
- CNetDemoApp::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
- outUsesMark = false;
-
- switch (inCommand) {
-
- // +++ Add cases here for the commands you handle.
- //
- // Set outEnabled to TRUE for commands that can be executed at
- // this time.
- //
- // If the associated menu items can have check marks, set
- // outUsesMark and outMark accordingly.
- //
- // Set outName to change the name of the menu item
-
- case cmd_New:
- outEnabled = true;
- break;
-
- default:
- LApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
- outMark, outName);
- break;
- }
- }
-
-
-
- void
- CNetDemoApp::SpawnSender(
- Boolean inSender)
-
- {
- StDialogHandler dlog(WIND_NewSession, this);
- MessageT msg = 0;
-
- while (!msg)
- msg = dlog.DoDialog();
-
- if (msg == msg_Cancel)
- return;
-
- LWindow *window = LWindow::CreateWindow(129, this);
-
- Str255 address;
- char configstr[80];
-
- LEditField* adrStr = (LEditField*) dlog.GetDialog()->FindPaneByID(pAddress);
- LStdRadioButton* tcpBut = (LStdRadioButton*) dlog.GetDialog()->FindPaneByID(pTCPButton);
-
- if (tcpBut->GetValue())
- strcpy(configstr, "udp");
- else
- strcpy(configstr, "ddp");
-
- adrStr->GetDescriptor(address);
- p2cstr(address);
-
-
- // for now we just create a sender
-
- volatile NetPoint* theNetPoint = nil;
-
- try {
-
-
- if (inSender)
- theNetPoint = new OutPoint(configstr, (char*) address, OUR_PORT);
- else
- theNetPoint = new InPoint(configstr, (char*) address, OUR_PORT);
-
-
- }
- catch(...) {
- delete theNetPoint;
- }
-
- DemoDoc* theDoc = new DemoDoc(this);
- theDoc->SetNetPoint(theNetPoint);
-
-
- }
-
-